﻿using BCTMSRESTful;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;

namespace BCTMSRESTful
{
    /// <summary>
    /// 系统主程序
    /// </summary>
    public class Program
    {
        /// <summary>
        /// 项目入口程序
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
#if DEBUG
            var config = new ConfigurationBuilder()
                        .AddEnvironmentVariables()
                        .AddCommandLine(args)
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("appsettings.hosting.json", optional: true)
                        .AddJsonFile($"appsettings.dev.json", optional: true)
                        .Build();
            Console.WriteLine(config["ASPNETCORE_ENVIRONMENT"] + "模式-DEBUG");
            CreateWebHostBuilder(args, config).Build().Run();
#else
            var config = new ConfigurationBuilder()
                        .AddEnvironmentVariables()
                        .AddCommandLine(args)
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("appsettings.hosting.json", optional: true)
                        .AddJsonFile($"appsettings.production.json", optional: true)
                        .Build();
            Console.WriteLine(config["ASPNETCORE_ENVIRONMENT"] + "模式-Production");
            CreateWebHostBuilder(args, config).Build().Run();
#endif
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args, IConfigurationRoot config) =>

        WebHost.CreateDefaultBuilder(args)
                .UseEnvironment(config["ASPNETCORE_ENVIRONMENT"])
                .UseConfiguration(config)
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>();
    }
}
